﻿// $Id: CacheManager.cs 10 2008-02-29 15:58:02Z mcartoixa $
/*
 *  Copyright (C) 2007 NourY Solutions
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */
/*! \file
 * \brief Definition of \c Salamanca.DataAccess.ICacheManager.
 *
 * \author $Author: mcartoixa $
 * \date $Date: 2008-02-29 16:58:02 +0100 (ven., 29 févr. 2008) $
 * \version $Revision: 10 $
 */

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;

namespace Salamanca.DataAccess
{



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Interface of a cache manager.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    public interface ICacheManager
    {

        /// <summary>Adds an element with the provided key and value to the <see cref="ICacheManager" />.</summary>
        void Add(object key, object value);

        /// <summary>Removes all keys and values from the <see cref="ICacheManager" />.</summary>
        void Clear();

        /// <summary>Determines whether the <see cref="ICacheManager" /> contains an element with the specified key.</summary>
        bool ContainsKey(object key);

        /// <summary>Removes the element with the specified key from the <see cref="ICacheManager" />.</summary>
        bool Remove(object key);

        /// <summary>Gets the value associated with the specified key.</summary>
        [SuppressMessage("Microsoft.Design", "CA1007:UseGenericsWhereAppropriate")]
        bool TryGetValue(object key, out object value);

        /// <summary>Gets or sets the element with the specified key.</summary>
        object this[object key]
        {
            get;
        }
    }



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Special cache manager that does not store any item.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    public sealed class NoCacheManager:
        ICacheManager
    {

        /// <summary>Constructor.</summary>
        public NoCacheManager()
        {
        }

        /// <summary>Adds an element with the provided key and value to the <see cref="NoCacheManager" />.</summary>
        void ICacheManager.Add(object key, object value)
        {
        }

        /// <summary>Removes all keys and values from the <see cref="NoCacheManager" />.</summary>
        void ICacheManager.Clear()
        {
        }

        /// <summary>Determines whether the <see cref="NoCacheManager" /> contains an element with the specified key.</summary>
        bool ICacheManager.ContainsKey(object key)
        {
            return false;
        }

        /// <summary>Removes the element with the specified key from the <see cref="NoCacheManager" />.</summary>
        bool ICacheManager.Remove(object key)
        {
            return false;
        }

        /// <summary>Gets the value associated with the specified key.</summary>
        bool ICacheManager.TryGetValue(object key, out object value)
        {
            value=null;
            return false;
        }

        /// <summary>Gets or sets the element with the specified key.</summary>
        object ICacheManager.this[object key]
        {
            get
            {
                throw new KeyNotFoundException();
            }
        }

    }
}
